home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / Photoshop 4.0 SDK r2 Mac / Examples / Selection / Selectorama / SelectoramaUIMac.c < prev   
Text File  |  1996-09-13  |  5KB  |  188 lines

  1. /*
  2.     File: SelectoramaUIMac.c
  3.  
  4.     Copyright 1996 by Adobe Systems, Inc.
  5.  
  6.     C source file for Mac specific code for Selection example.
  7. */
  8.  
  9. #include "Selectorama.h"
  10. #include "DialogUtilities.h"
  11.  
  12. /*****************************************************************************/
  13.  
  14. /* Displays the about dialog box for the plug-in module. */
  15.  
  16. void DoAbout (GPtr globals)
  17. {
  18.     ShowAbout(gStuff->hostSig, AboutID);
  19. }
  20.  
  21. /*****************************************************************************/
  22.  
  23. /* Setup the parameters dialog.  Returns TRUE if it succeeds.                 */
  24.  
  25. Boolean DoParameters (GPtr globals)
  26. {
  27.     
  28.     short         item, lastitem;
  29.     short         lastArea = gWhatArea;
  30.     short        lastChannels = gWhatChannels;
  31.     short        lastPercent = gPercent;
  32.     short        numberErr = noErr;
  33.     long        x;
  34.     DialogPtr    dp;
  35.     DialogTHndl    dialogHdl;
  36.     dialogHdl = (DialogTHndl) GetResource ('DLOG', uiID);
  37.  
  38.     if (dialogHdl == NULL || *dialogHdl == NULL)
  39.         return false;
  40.     else
  41.     {
  42.         
  43.     HNoPurge ((Handle) dialogHdl);
  44.  
  45.     CenterDialog (dialogHdl);
  46.     SetUpMoveableModal (dialogHdl, gStuff->hostSig);
  47.     
  48.     dp = GetNewDialog (uiID, nil, (WindowPtr) -1);
  49.         
  50.     /* I am throwing away the results from these routines. 
  51.        Toolbox TechNote 37 does not document what error values they return.
  52.        Also, the worst that happens is that the interface isn't quite right. */
  53.     
  54.     (void) SetDialogDefaultItem (dp, ok);
  55.     (void) SetDialogCancelItem (dp, cancel);
  56.     (void) SetDialogTracksCursor (dp, TRUE);
  57.         
  58.     SetRadioGroupState (dp,
  59.                         kFirstItem,
  60.                         kLastItem,
  61.                         kFirstItem + gWhatArea);
  62.                         
  63.     SetRadioGroupState (dp,
  64.                         kUseRadio1,
  65.                         kUseRadioLast,
  66.                         kUseRadio1 + gWhatChannels);
  67.  
  68.     SetRadioGroupState (dp,
  69.                         kCreateRadio1,
  70.                         kCreateRadioLast,
  71.                         kCreateRadio1 + gCreate);
  72.     
  73.     ShowHideItem (dp, kPercentStatic, (gWhatArea == iSelectRandom));
  74.     ShowHideItem (dp, kPercentEdit, (gWhatArea == iSelectRandom));
  75.     ShowHideItem (dp, kPercentSymbol, (gWhatArea == iSelectRandom));
  76.     StuffNumber(dp, kPercentEdit, gPercent);
  77.     if (gWhatArea == iSelectRandom) SelectTextItem(dp, kPercentEdit);
  78.         
  79.     SelectWindow (dp);
  80.     
  81.     do
  82.     {
  83.         
  84.         MoveableModalDialog (dp, gStuff->processEvent, nil, &item);
  85.         
  86.         if (lastitem != item && item != cancel)
  87.         { /* we just left this area.  Check to make sure its within bounds. */
  88.             switch (lastitem)
  89.             {
  90.                 case kPercentEdit:
  91.                     numberErr = FetchNumber(dp,
  92.                                             kPercentEdit,
  93.                                             kPercentMin,
  94.                                             kPercentMax,
  95.                                             &x);
  96.                     if (numberErr != noErr)
  97.                     { // shows alert if there's an error
  98.                         AlertNumber(dp,
  99.                                     kPercentEdit,
  100.                                     kPercentMin,
  101.                                     kPercentMax,
  102.                                     &x,
  103.                                     hDllInstance,
  104.                                     AlertID,
  105.                                     numberErr);
  106.                         item = kPercentEdit; // stay here
  107.                     }
  108.                     gPercent = x;                        
  109.                     break;
  110.             }
  111.         }
  112.         switch (item)
  113.         {
  114.             case ok:
  115.                 gWhatArea = GetRadioGroupState(dp, kFirstItem, kLastItem) - kFirstItem;
  116.                 gWhatChannels = GetRadioGroupState(dp, kUseRadio1, kUseRadioLast) - kUseRadio1;
  117.                 gCreate = GetRadioGroupState(dp, kCreateRadio1, kCreateRadioLast) - kCreateRadio1;
  118.                 if (gWhatArea == iSelectRandom)
  119.                 {
  120.                     numberErr = FetchNumber(dp,
  121.                                             kPercentEdit,
  122.                                             kPercentMin,
  123.                                             kPercentMax,
  124.                                             &x);
  125.                     if (numberErr != noErr)
  126.                     { // shows alert if there's an error
  127.                         AlertNumber(dp,
  128.                                     kPercentEdit,
  129.                                     kPercentMin,
  130.                                     kPercentMax,
  131.                                     &x,
  132.                                     hDllInstance,
  133.                                     AlertID,
  134.                                     numberErr);
  135.                         item = kPercentEdit; // go back
  136.                     }
  137.                     else gPercent = x; // it's okay, move on
  138.                 }
  139.                 break;
  140.  
  141.             case cancel:
  142.                 gResult = userCanceledErr;
  143.                 break;
  144.             case kPercentEdit:
  145.                 // grab the number whether it's right or not
  146.                 numberErr = FetchNumber(dp, kPercentEdit, kPercentMin, kPercentMax, &x);
  147.                 if (numberErr == noErr)
  148.                 { // no errors getting the number
  149.                     gPercent = x;
  150.                     // update display here     
  151.                 }
  152.                 break;
  153.  
  154.             default:
  155.             if (item >= kFirstItem && item <= kLastItem)
  156.             {
  157.                 SetRadioGroupState (dp, kFirstItem, kLastItem, item);
  158.                 ShowHideItem (dp, kPercentStatic, (item == iSelectRandom + kFirstItem));
  159.                 ShowHideItem (dp, kPercentEdit, (item == iSelectRandom + kFirstItem));
  160.                 ShowHideItem (dp, kPercentSymbol, (item == iSelectRandom + kFirstItem));
  161.                 if (item == iSelectRandom + kFirstItem) SelectTextItem(dp, kPercentEdit);
  162.             }
  163.             else if (item >= kUseRadio1 && item <= kUseRadioLast)
  164.                 SetRadioGroupState (dp, kUseRadio1, kUseRadioLast, item);
  165.             else if (item >= kCreateRadio1 && item <= kCreateRadioLast)
  166.                 SetRadioGroupState (dp, kCreateRadio1, kCreateRadioLast, item);
  167.             break;
  168.         }
  169.         lastitem = item;
  170.     }
  171.     while (item != ok && item != cancel);
  172.  
  173.     DisposDialog (dp);
  174.         
  175.     if (dialogHdl != NULL && *dialogHdl != NULL)
  176.         HPurge ((Handle) dialogHdl);
  177.     
  178.     dp = NULL;
  179.     dialogHdl = NULL;
  180.     
  181.     return item == ok;
  182.     
  183.     
  184.     } // else
  185. }
  186.  
  187. /*********************************************************************/
  188.